<!--
 * @FilePath     : /study_code/wangEditor/11-4.html
 * @Description  : 设置 HTML格式 内容
 * @Date         : 2025-04-07 23:02:49
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-07 23:10:23
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/@wangeditor/editor/dist/css/style.css" />
    <link rel="stylesheet" href="/wangEditor/common/style.css" />
  </head>
  <body>
    <button id="btn1">设置动态 HTML 内容</button>
    <button id="btn2">设置加粗内容1</button>
    <button id="btn3">设置加粗内容2</button>

    <hr />

    <div id="editor—wrapper">
      <div id="toolbar-container"><!-- 工具栏 --></div>
      <div id="editor-container"><!-- 编辑器 --></div>
    </div>

    <script src="/@wangeditor/editor/dist/index.js"></script>
    <script>
      const { createEditor, createToolbar } = window.wangEditor

      const editorConfig = {
        placeholder: 'Type here...',
      }

      const editor = createEditor({
        selector: '#editor-container',
        html: '<p><br></p>',
        config: editorConfig,
        mode: 'default', // or 'simple'
      })

      /* const toolbarConfig = {}

      const toolbar = createToolbar({
        editor,
        selector: '#toolbar-container',
        config: toolbarConfig,
        mode: 'default', // or 'simple'
      }) */

      // --------------------------------------------

      btn1.addEventListener(
        'click',
        function (e) {
          editor.setHtml('<p>翩若惊鸿，婉若游龙。</p>')
        },
        false
      )

      btn2.addEventListener(
        'click',
        function (e) {
          editor.setHtml('<strong>great wall</strong>')
        },
        false
      )

      btn3.addEventListener(
        'click',
        function (e) {
          editor.setHtml('<span style="font-weight: bold;">hello</span>')
          // 设置后，内容被解析为 <span data-slate-string="true">hello</span>
        },
        false
      )
    </script>
  </body>
</html>
